define(['app'], function(app) {
	'use strict';

	var controller = function controller($scope, $rootScope, $window, $timeout, Store_data, Center, GoPage, GoDialog, Auth, $ionicActionSheet, $ionicSideMenuDelegate, GoRegion, GoBrandCat, $ionicLoading, GoCheck, GoMap, GoPicture, GoCatTypeAuth) {
		$scope.isLoad = false; //可以加载
		$scope.showMap = false;
		$scope.data = new Object();
		$scope.data.store = new Object();
		$scope.data.catShow = new Array(); //显示用，不提交
		$scope.data.store_region = {
			package: '',
			data: {
				list1: [],
				value1: '',
				value1_select: {id:0,name:"请选择"},
				list2: [],
				value2: '',
				value2_select: {id:0,name:"请选择"},
				list3: [],
				value3: '',
				value3_select: {id:0,name:"请选择"},
			}
		};
		$scope.cgender_items = [{id:"male",name:"男"},{id:"female",name:"女"}];
		$scope.company_cgender_select = {id:"",name:"请选择性别"};
		$scope.contact_gender_select = {id:"",name:"请选择性别"};
		$scope.doSelectSex = function(type){
			//id是值 name是显示
			if(type == 1){
				GoDialog.showSelect("类型",$scope.cgender_items,$scope.company_cgender_select,function(data){
					$scope.data.store.company_cgender = data.id;
					$scope.company_cgender_select = data;
				});
			}else{
				GoDialog.showSelect("类型",$scope.cgender_items,$scope.contact_gender_select,function(data){
					$scope.data.store.contact_gender = data.id;
					$scope.contact_gender_select = data;
				});
			}
		}
		$scope.store_grade_select = {id:"",name:"请选择"};
		$scope.doSelectGrade = function(){
			var list = new Array();
			$scope.data.grade_list.forEach(obj => {
				if(obj.id == undefined)
				obj.id = obj.grade_id;
				if(obj.name == undefined)
				obj.name = obj.issue_name;
				list.push(obj);
			});
			//id是值 name是显示
			GoDialog.showSelect("企业类型",list,$scope.store_grade_select,function(data){
				$scope.data.store.store_grade = data.id;
				$scope.store_grade_select = data;
				$scope.change_grade();
			});
		}
		$scope.business_select = {id:"",text:"请选择"};
		$scope.doSelectBusiness = function(type){
			if(type == 1)return;
			var list = new Array();
			$scope.data.business_type_list.forEach(obj => {
				if(obj.id == undefined)
				obj.id = obj.value;
				list.push(obj);
			});
			//id是值 name是显示
			GoDialog.showSelect("经营性质",list,$scope.business_select,function(data){
				$scope.data.store.business_type = data.id;
				$scope.business_select = data;
			});
		}
		$scope.check_Login = function() {
			return Auth.check_loginInfo();
		}

		//画面加载
		$scope.$on('$ionicView.afterEnter', function(scope, status) {
			//动态设置高度
			GoPage.init_top($scope, 0, 0);
			$scope.map_height = Math.floor($window.innerWidth / 2.75);
			if(status.direction != 'back') {
				$scope.init_data();
			}
		}, false);

		// 重新获取用户信息
		$scope.init_data = function(cbComplete) {
			var Infos = Auth.get_loginInfo();
			if(!Infos) {
				GoDialog.toast('未登录');
				return;
			}

			Store_data.get_store({
				'session': Infos.user_id
			}, function(res) {
				if(res.success != true) {
					GoDialog.toast(res.msg);
					return;
				}
				var info = res.result;
				console.log(info)
				if(!(info.grade && info.grade.length > 0)) {
					GoDialog.toast('数据异常');
					return;
				}

				var s = info.store || {};
				var data = $scope.data;
				data.store = s;
				if($scope.data.store.store_cat == undefined || $scope.data.store.store_cat == null) { //防止初始时没有数据报错
					$scope.data.store.store_cat = new Array();
				}
				$scope.getCatShow(); //组装要显示的主营分类
				data.store_brand = info.store_brand;
				data.brand = info.brand;
				data.grade_list = info.grade || [];
				for(var i = data.grade_list.length - 1; i >= 0; i--) {
					var g = data.grade_list[i];
					if(g.issue_type == '1') {
						// g.grade_name = '制造商';
					} else if(g.issue_type == '2') {
						// g.grade_name = '品牌运营商';
					} else if(g.issue_type == '3') {
						// g.grade_name = '代理商';
					} else if(g.issue_type == '4') {
						// g.grade_name = '经销商';
					} else {
						data.grade_list.splice(i, 1);
					}
				}
				// 根据grade设置画面
				if(!s.store_id) {
					data.approved_text = '请申请店铺';
					data.store.store_grade = info.grade[0].grade_id;
				} else {
					data.approved = s.approved;
					var approved_text = '';
					if(s.approved == '0') {
						approved_text = '审核中';
					} else if(s.approved == '1') {
						approved_text = '审核通过';
					} else if(s.approved == '2') {
						approved_text = '审核未通过';
					}
					data.approved_text = approved_text;

					// 企业类型
					data.issue_type_text = s.issue_type_name;
					if(s['is_warehouse'] == 'Y') {
						data.issue_type_text = "分仓";
					}
				}

				$scope.change_grade();

				// 内销外销
				data.is_domestic = s.is_domestic == 'Y' ? true : false;
				data.is_export = s.is_export == 'Y' ? true : false;

				// 公司地址
				var area = data.store.company_area || '';
				var index = area.indexOf(':');
				if(index >= 0) {
					area = area.substring(index + 1);
					index = area.indexOf(':');
					if(index >= 0) {
						area = area.substring(0, index);
						data.store_company_area = area.replace(new RegExp('/', 'gm'), ' > ');
					}
				}

				// 推荐
				//				if(s.regist_source_recommend || !s.regist_source_other_type) {
				//					data.regist_source_flg1 = true;
				//				} else {
				//					data.regist_source_flg1 = false;
				//				}
				//				data.regist_source_flg2 = !data.regist_source_flg1;

				$scope.isLoad = true;

				initRegionSelect(function() {
					if(s.store_id && s.approved == '1') {
						var cats = s.store_cat || [];
						var cat_list = [];
						for(var i = 0; i < cats.length; i++) {
							var index = cats[i].indexOf(':');
							if(index >= 0) {
								var c = cats[i].substring(0, index) || '';
								cat_list.push(c.replace(new RegExp('/', 'gm'), ' > '));
							}
						}
						data.cat_list = cat_list;

						$scope.set_CompanyLocation();
					} else {
						$scope.set_CompanyLocation();
					}
				});

			}, null, cbComplete)
		}

		// 切换推荐
		//		$scope.change_regist_source = function(flg) {
		//			$scope.data.regist_source_flg1 = (flg == 1);
		//			$scope.data.regist_source_flg2 = (flg == 2);
		//		}

		// 切换分仓
		$scope.change_is_warehouse = function(is_warehouse) {
			var s = $scope.data.store;
			if(s.issue_type == '3') {
				$scope.data.is_warehouse = is_warehouse
				$scope.data.is_not_warehouse = !$scope.data.is_warehouse;

				$scope.data.store.is_warehouse = is_warehouse ? 'Y' : 'N';

				$scope.data.issue_type_text = s.issue_type_name;
				if(is_warehouse) {
					$scope.data.issue_type_text = "分仓";
				}
			} else {
				$scope.data.store.is_warehouse = null;
			}

		}

		// 切换店铺类型
		$scope.change_grade = function() {
			var s = $scope.data.store;
			var grade_id = s.store_grade;

			var issue_type;
			var grade_list = $scope.data.grade_list;
			for(var i = 0; i < grade_list.length; i++) {
				var g = grade_list[i];
				if(g.grade_id == grade_id) {
					issue_type = g.issue_type;
				}
			}
			s.issue_type = issue_type;

			// 分仓
			$scope.change_is_warehouse(s.is_warehouse == 'Y')

			if(issue_type == '1' || issue_type == '4') {
				// 经营性质
				if(issue_type == '1') {
					$scope.data.business_type_list = [{
							value: 'm_product',
							text: '产品制造商'
						},
						{
							value: 'm_parts',
							text: '配件制造商'
						},
						{
							value: 'm_industry',
							text: '行业生产'
						},
						{
							value: 'm_equipment',
							text: '设备制造商'
						}
					];
				} else if(issue_type == '4') {
					$scope.data.business_type_list = [{
							value: 'f_physical',
							text: '实体店（实体店+网店，实体店+贸易商）'
						},
						{
							value: 'f_online',
							text: '网店（实体店+贸易商）'
						},
						{
							value: 'f_trader',
							text: '贸易商'
						}
					];
				}
				var has_business_type = false;
				for(var i = 0; i < $scope.data.business_type_list.length; i++) {
					if(s.business_type == $scope.data.business_type_list[i].value) {
						has_business_type = true;
						break;
					}
				}
				if(!has_business_type) {
					s.business_type = '';
				}
			}

			// 图片
			var picname = '';
			if(issue_type == "1") picname = '厂区';
			if(issue_type == "2") picname = '总部';
			if(issue_type == "3") picname = '库房';
			if(issue_type == "4") picname = '经营场所';
			$scope.data.picname = picname;
		}

		function trim(val) {
			return typeof val == 'string' ? val.trim() : val
		}

		function checkRequired(val, name) {
			if(!trim(val)) {
				GoDialog.toast('必须输入' + name);
				return false;
			}

			return true;
		}

		function checkUpdate() {

			var s = $scope.data.store;
			var data = $scope.data;
			for(var k in s) s[k] = trim(s[k]);

			if(!(s.store_id && s.approved == 1)) {
				if(!checkRequired(s.store_name, '店铺名称')) return
			}

			if(!(s.issue_type == '3' && data.is_warehouse)) {

				if(!(s.store_id && s.approved == 1)) {
					if(!checkRequired(s.company_name, '公司名称')) return
					if(!checkRequired(s.company_no, '统一社会信用代码')) return
					if(!GoCheck.checkAlphaAndNumber(s.company_no)) {
						GoDialog.toast('请输入正确的统一社会信用代码');
						return;
					}

					if(s.issue_type == "4") {
						if(!checkRequired(s.company_idname, '法人姓名')) return
						if(!GoCheck.checkZhstr(s.company_idname)) {
							GoDialog.toast('请输入正确的法人姓名');
							return;
						}

						if(!checkRequired(s.company_idcard, '法人身份证号')) return

						var testIDMsg = GoCheck.testID(s.company_idcard);
						if(testIDMsg != 'true') {
							GoDialog.toast(testIDMsg);
							return;
						}
					}

					if(!checkRequired(s.company_remark, '经营范围')) return
				}

				if(!(s.store_id && s.approved == 1)) {
					if(s.issue_type == "1" || s.issue_type == "2") {
						if(!data.is_domestic && !data.is_export) {
							GoDialog.toast('请选择销售类型');
							return;
						}

						s.is_domestic = data.is_domestic ? 'Y' : 'N';
						s.is_export = data.is_export ? 'Y' : 'N';
					}

					if(s.issue_type == "1" || s.issue_type == "4") {
						if(!checkRequired(s.business_type, '经营性质')) return
					}
				}

			} else {
				if(s.approved != 1) {
					if(!checkRequired(s.relation_manu_store_id, '相关制造商')) return
				}
			}

			if(!(s.store_id && s.approved == 1)) {
				if(!checkRequired(s.company_area, '公司地区')) return
				if(!checkRequired(s.company_addr, '公司详细地址')) return
				if(!s.company_lng || !s.company_lat) {
					GoDialog.toast('请对公司地址进行定位');
					return;
				}
				// s.company_lng = 121.59095;
				// s.company_lat = 31.213446;

				// 主营品类
				if(!(s.issue_type == '3' && data.is_warehouse)) {
					var cats = $scope.data.store.store_cat;
					if(!cats || cats.length == 0) {
						GoDialog.toast('请选择主营分类');
						return
					}

					var hasCats = false;
					for(var i = cats.length - 1; i >= 0; i--) {
						if(!cats[i] || !cats[i].trim()) {
							cats.splice(i, 1);
							continue;
						}

						// 去除重复
						var hasSame = false;
						for(var j = 0; j < i; j++) {
							if(cats[i] == cats[j]) {
								hasSame = true;
								cats.splice(i, 1);
								break;
							}
						}
						if(hasSame) continue;

						hasCats = true;
					}

					if(!hasCats) {
						GoDialog.toast('请选择主营分类');
						return
					}
				}
			}

			// 非分仓
			if(!(s.issue_type == '3' && data.is_warehouse)) {
				if(!checkRequired(s.company_profile, '企业简介')) return
			}

			if(s.company_cname && !GoCheck.checkZhstr(s.company_cname)) {
				GoDialog.toast('请输入正确的负责人姓名');
				return;
			}
			if(!checkRequired(s.contact_name, '联系人姓名')) return
			if(!GoCheck.checkZhstr(s.contact_name)) {
				GoDialog.toast('请输入正确的联系人姓名');
				return;
			}
			if(!checkRequired(s.contact_mobile, '联系人手机')) return
			if(!GoCheck.checkMobile(s.contact_mobile)) {
				GoDialog.toast('请输入正确的联系人手机号码');
				return;
			}
			if(s.contact_number && !GoCheck.checkTel(s.contact_number)) {
				GoDialog.toast('请输入正确的联系人固话号码');
				return;
			}
			if(s.contact_qq && !GoCheck.checkNumber(s.contact_qq)) {
				GoDialog.toast('请输入正确的联系人QQ号码');
				return;
			}
			if(s.contact_email && !GoCheck.checkEmail(s.contact_email)) {
				GoDialog.toast('请输入正确的联系人EMail');
				return;
			}

			// 非分仓
			if(!(s.issue_type == '3' && data.is_warehouse)) {
				//（1）“途径-开发”不可以修改
				//				if(!(s.store_id && s.store_id == 1)) {
				//					if(!checkRequired(s.regist_source_code, '途径-开发')) return
				//					if(!data.regist_source_flg1 && !data.regist_source_flg2 ||
				//						data.regist_source_flg1 && !trim(s.regist_source_recommend) ||
				//						data.regist_source_flg2 && (!s.regist_source_other_type || !s.regist_source_other)) {
				//
				//						GoDialog.toast('需要选填一个【开发】以外的注册途径');
				//						return;
				//					}
				//				}
				//（2）“营业执照”不可以修改
				//				if(!s.image_cid || s.image_cid.length == 0) {
				//					GoDialog.toast('请上传营业执照');
				//					return;
				//				}

				if(s.issue_type == "2" && (!s.image_cert1 || s.image_cert1.length == 0)) {
					GoDialog.toast('请上传品牌证书');
					return;
				}

				if(!s.image_place1 || !s.image_place2 ||
					(s.issue_type != "4" && (!s.image_place3 || !s.image_place4))) {

					var picname = '';
					if(s.issue_type == "1") picname = '厂区';
					if(s.issue_type == "2") picname = '总部';
					if(s.issue_type == "3") picname = '库房';
					if(s.issue_type == "4") picname = '经营场所';

					GoDialog.toast('请上传全部' + picname + '照片');
					return;
				}
			}

			return true;
		}

		// 保存
		$scope.do_save = function() {
			var Infos = Auth.get_loginInfo();
			if(!Infos) {
				GoDialog.toast('未登录');
				return;
			}
			if(checkUpdate() != true) return;
			var s = $scope.data.store;
			var data = $scope.data;
			//			if(data.regist_source_flg1) {
			//				s.regist_source_flg = '1';
			//				s.regist_source_other_type = '';
			//				s.regist_source_other = '';
			//			}
			//			if(data.regist_source_flg2) {
			//				s.regist_source_flg = '2';
			//				s.regist_source_recommend = '';
			//			}

			delete s['image_cid_path'];
			delete s['image_licence_path'];
			delete s['image_cert1_path'];
			delete s['image_cert2_path'];
			delete s['image_place1_path'];
			delete s['image_place2_path'];
			delete s['image_place3_path'];
			delete s['image_place4_path'];
			delete s['image_id_path'];
			delete s['image_id2_path'];

			// 保存
			console.log($scope.data.store)
			Store_data.save_store({
				'updateParams': JSON.stringify($scope.data.store)
			}, function(res) {
				if(res.success != true) {
					GoDialog.toast(res.msg);
					return;
				}
				GoDialog.toast('保存成功');
				refresh_auth();
				var Infos = Auth.get_loginInfo();
				if(Infos.store_id != "") {
					Infos.issue_type = 2;
					Auth.save_loginInfo_change(Infos);
				}
				$scope.init_data();
			}, function(e) {
				GoDialog.toast("Connecting error, try again...");
			}, function() {

			})
		}

		// 生成公司地区值
		function setCompanyArea() {
			var sr = $scope.data.store_region;
			var name = '';
			var value = '';
			for(var i = 1; i <= 3; i++) {
				var v = sr.data['value' + i];
				if(v) {
					var l = sr.data['list' + i]
					for(var j = 0; j < l.length; j++) {
						if(v == l[j].id) {
							if(name) name += '/';
							name += l[j].text;
							value = v;
							break;
						}
					}
				} else {
					break;
				}
			}

			if(value) {
				$scope.data.store.company_area = sr.package + ':' + name + ':' + value;
				$scope.data.company_area_name = name;
			} else {
				$scope.data.store.company_area = '';
				$scope.data.company_area_name = '';
			}
		}
		$scope.doSelectProvince = function(){
			//id是值 name是显示
			GoDialog.showSelect("请选择省份",$scope.data.store_region.data.list1,$scope.data.store_region.data.value1_select,function(data){
				$scope.data.store_region.data.value1 = data.id;
				$scope.data.store_region.data.value1_select = data;
				$scope.change_Regionselect(1);
			});
		}
		$scope.doSelectCity = function(){
			//id是值 name是显示
			GoDialog.showSelect("请选择城市",$scope.data.store_region.data.list2,$scope.data.store_region.data.value2_select,function(data){
				$scope.data.store_region.data.value2 = data.id;
				$scope.data.store_region.data.value2_select = data;
				$scope.change_Regionselect(2);
			});
		}
		$scope.doSelectDistrict = function(){
			//id是值 name是显示
			GoDialog.showSelect("请选择区/县",$scope.data.store_region.data.list3,$scope.data.store_region.data.value3_select,function(data){
				$scope.data.store_region.data.value3 = data.id;
				$scope.data.store_region.data.value3_select = data;
				$scope.change_Regionselect(3);
			});
		}
		// 地域三级联动下拉框发生变动
		$scope.change_Regionselect = function(lvl) {
			if(lvl == 3) {
				setCompanyArea();
				return;
			}

			var sr = $scope.data.store_region;
			var selected_id = sr.data['value' + lvl];
			GoRegion.get_nextlvl(selected_id, lvl, sr.data, null, null, function() {
				// done
				setCompanyArea()
			})
		}

		// 地域初始化
		function initRegionSelect(cb) {
			try {
				var area = $scope.data.store.company_area || '';
				// 初始化地区三级联动
				GoRegion.init(area, function(success, initdata, packageName) {
					if(!success) {
						return;
					}

					$scope.data.store_region.package = packageName;
					$scope.data.store_region.data = initdata;

				}, function() {

				}, function() {
					setCompanyArea();
					cb && cb();
				})
			} catch(ex) {
				cb && cb();
			}
		}

		//获取分类，格式：大分类名/中分类名/小分类名:最后一级分类的id
		$scope.getCat = function() {
			var cat = "";
			var cat_name = "";
			if($scope.input.cat3) {
				cat_name = $scope.input.cat1.name + "/" + $scope.input.cat2.name + "/" + $scope.input.cat3.name;
				cat = cat_name + ":" + $scope.input.cat3.id;
			} else if($scope.input.cat2) {
				cat_name = $scope.input.cat1.name + "/" + $scope.input.cat2.name;
				cat = cat_name + ":" + $scope.input.cat2.id;
			} else if($scope.input.cat1) {
				cat_name = $scope.input.cat1.name;
				cat = cat_name + ":" + $scope.input.cat1.id;
			}
			return cat;
		}

		//添加分类 
		$scope.add_StoreCat = function() {
			var cat = $scope.getCat();
			if(!cat) {
				GoDialog.toast("请先选择品类！");
				return;
			}
			for(var i = 0; i < $scope.data.store.store_cat.length; i++) {
				if(cat == $scope.data.store.store_cat[i]) {
					GoDialog.toast("请勿重复添加品类！");
					return;
				}
			}
			$scope.data.store.store_cat.push(cat);
			$scope.getCatShow();
		}

		// 删除分类
		$scope.remove_StoreCat = function(index) {
			$scope.data.store.store_cat.splice(index, 1);
			$scope.getCatShow();
		}

		//显示用
		$scope.getCatShow = function() {
			var index = 0;
			var cat = "";
			$scope.data.catShow = new Array(); //显示用，不提交
			for(var i = 0; i < $scope.data.store.store_cat.length; i++) {
				index = $scope.data.store.store_cat[i].indexOf(":");
				cat = $scope.data.store.store_cat[i].substr(0, index);
				$scope.data.catShow.push(cat);
			}
		}

		$scope.do_location = function() {
			var area = $scope.data.company_area_name;
			if(area) {
				area = area.replace(new RegExp(/(\/)/g), '')
			}

			var addr = trim($scope.data.store.company_addr);

			if(!area || !addr) {
				GoDialog.toast('请输入完整地址');
				return;
			}

			var comaddr = area + addr

			$ionicLoading.show({
				template: '定位中...'
			});

			getLocation('company_addr_map', comaddr, function(point) {
				$ionicLoading.hide();

				var s = $scope.data.store;
				if(!point) {
					GoDialog.toast('没有定位成功');
					s.company_lng = null;
					s.company_lat = null;
				} else {
					GoDialog.toast('成功定位');
					s.company_lng = point.lng;
					s.company_lat = point.lat;
				}
				$scope.set_CompanyLocation();
			});
		}

		$scope.set_CompanyLocation = function() {
			var s = $scope.data.store;
			var company_area = trim(s.company_area);
			var addr = trim(s.company_addr);

			if(s.company_lng && s.company_lat && s.company_area) {
				if(company_area) {
					try {
						company_area = company_area.substring(company_area.indexOf(":") + 1);
						company_area = company_area.substring(0, company_area.indexOf(":"));
						company_area = company_area.replace(new RegExp('\/', 'gm'), '');
					} catch(e) {
						company_area = "";
					}
				}
				setLocation('company_addr_map', company_area + addr, s.company_lng, s.company_lat);
			} else {
				GoMap.get_currentlocation(function(point) {
					GoMap.set_location('company_addr_map', [{
						lng: point.lng,
						lat: point.lat,
						no_flag: true
					}], {
						Dragging: false,
						ScrollWheelZoom: false,
						DoubleClickZoom: false,
						Keyboard: false,
						InertialDragging: false,
						ContinuousZoom: false,
						PinchToZoom: false
					})
				})
			}

		}

		function getLocation(container_id, keyword, callback) {

			GoMap.get_location(container_id, keyword, callback);

		}

		function setLocation(container_id, content, lng, lat) {

			GoMap.set_location(container_id, [{
				content: content,
				lng: lng,
				lat: lat
			}], {
				Dragging: false,
				ScrollWheelZoom: false,
				DoubleClickZoom: false,
				Keyboard: false,
				InertialDragging: false,
				ContinuousZoom: false,
				PinchToZoom: false
			})
		}

		function refresh_auth(cbComplete) {

			if(Auth.check_loginInfo()) {
				var Infos = Auth.get_loginInfo();
				Center.get_AuthInfo({
					'session': Infos.user_id
				}, function(res) {
					if(res.success == true) {
						var info = res.result;
						for(var k in info) {
							if(info[k] == null || info[k] == undefined) {
								info[k] = '';
							}
						}
						//更新用户信息
						info.autologin_token_ios = ionic.Platform.isIOS() ? localStorage.getItem("token") : "";
						info.autologin_token_android = ionic.Platform.isIOS() ? "" : localStorage.getItem("token");
						Auth.save_loginInfo(info);
					}
				}, null, cbComplete)
			}
		}

		// 上传图片
		$scope.addStoreImg = function(type) {
			var isArray = false;
			if(type == 'image_licence' || type == 'image_cert1' || type == 'image_cert2') {
				isArray = true;
			}

			GoPicture.upload(function(res) {
				if(!res.success) {
					GoDialog.toast(res.msg);
					return;
				}

				var r = res.result;
				var s = $scope.data.store
				if(!isArray) {
					s[type] = r.image_id;
					s[type + '_path'] = r.image_src;
				} else {
					if(!s[type] || s[type].length == undefined) {
						s[type] = [];
						s[type + '_path'] = [];
					}
					s[type].push(r.image_id);
					s[type + '_path'].push(r.image_src);
				}

				GoDialog.toast(res.msg);
			});
		}

		$scope.openFileActSheet = function(type, index) {
			var src = $scope.data.store[type + '_path'];

			var isArray = false;
			if(type == 'image_licence' || type == 'image_cert1' || type == 'image_cert2') {
				isArray = true;
			}
			if(isArray) {
				src = src[index];
			}

			var buttons = new Array();
			buttons.push({
				text: '删除图片',
				style: ''
			});
			buttons.push({
				text: '显示大图',
				style: ''
			});

			GoDialog.sheet('图片操作', '取消', buttons, function(bindex) {

				if(bindex == 0) {
					GoDialog.confirm('删除图片', '是否要删除该图片？', function() {
						$scope.sheetActionRemove(type, index, isArray);
					})
				} else if(bindex == 1) {
					GoDialog.showBigImg();
				}
			});
		}

		$scope.sheetActionRemove = function(type, index, isArray) {
			var s = $scope.data.store

			if(!isArray) {
				s[type] = null;
				s[type + '_path'] = null;
			} else {
				s[type].splice(index, 1);
				s[type + '_path'].splice(index, 1);
			}
		}

		$scope.do_warehouse_upgrade = function() {
			GoPage.go_states("warehouse-upgrade");
		}

		$scope.select_relation_manu = function() {
			GoPage.go_states("searchpro-manufactor");
		}
		$rootScope.$on('warehouseSelectRelativeManu', function(event, data) {
			$scope.data.store.relation_manu_store_id = data.id;
			$scope.data.store.relation_manu_store_name = data.name;
		})

		/**********************张，修改*************************/
		$scope.input = new Object();
		/***分类三级联动***/
		$scope.input.cat1 = "";
		$scope.input.cat2 = "";
		$scope.input.cat3 = "";
		//下拉侦听
		$scope.listen_cat1 = function(data) {
			$scope.input.cat2 = "";
			$scope.input.cat3 = "";
			$scope.cat3_items = '';
		};
		$scope.listen_cat2 = function(data) {
			$scope.input.cat3 = "";
		};
		var items_cat = new Array();
		var obj1_cat = {
			name: 'input.cat1'
		};
		var obj2_cat = {
			name: 'input.cat2'
		};
		var obj3_cat = {
			name: 'input.cat3'
		};
		items_cat.push(obj1_cat);
		items_cat.push(obj2_cat);
		items_cat.push(obj3_cat);
		GoCatTypeAuth.init_load_only($scope, items_cat);
		$scope.doSelectCat1 = function(){
			//id是值 name是显示
			GoDialog.showSelect("大分类",$scope.cat1_items,$scope.input.cat1,function(data){
				$scope.input.cat1 = data;
			});
		}
		$scope.doSelectCat2 = function(){
			//id是值 name是显示
			GoDialog.showSelect("中分类",$scope.cat2_items,$scope.input.cat2,function(data){
				$scope.input.cat2 = data;
			});
		}
		$scope.doSelectCat3 = function(){
			//id是值 name是显示
			GoDialog.showSelect("小分类",$scope.cat3_items,$scope.input.cat3,function(data){
				$scope.input.cat3 = data;
			});
		}
	}

	controller.$inject = ['$scope', '$rootScope', '$window', '$timeout', 'Store_data', 'Center', 'GoPage', 'GoDialog', 'Auth', '$ionicActionSheet', '$ionicSideMenuDelegate', 'GoRegion', 'GoBrandCat', '$ionicLoading', 'GoCheck', 'GoMap', 'GoPicture', 'GoCatTypeAuth'];

	return app.registerController("store_datactrl", controller);
});